home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2787 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. Path: news.itsnet.com!ip47
  2. From: jeffp@itsnet.com (Jeff Petersen)
  3. Newsgroups: rec.games.programmer,comp.lang.c,comp.lang.c++
  4. Subject: Re: Watcom and Available Memory
  5. Date: Fri, 19 Jan 96 16:59:58 GMT
  6. Organization: Artificial Software
  7. Message-ID: <4dokk1$stk@itchy.itsnet.com>
  8. References: <4do475$1da@oznet07.ozemail.com.au>
  9. NNTP-Posting-Host: ip47.itsnet.com
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. > Hi.  I have Watcom C++ v10 and I need a way to find out how much free
  13. >RAM is left available to allocate.  I've played with _heapwalk() and
  14. >memaval etc and they only report about 3k available.  I have 32mb of
  15. >RAM.  I'm doing this with DOS/4GW and wpp386.  If anyone knows a way
  16. >of reporting the entire FREE RAM space I'd be greatful if they were to
  17. >share it with me.  Preferably I'd like to know if there is a standard
  18. >way of finding the entire free "core" area under any C or C++ system.
  19. >I there is none i think it's a gapping hole in the standard.
  20.  
  21. Better get used to not knowing; it is a bad habit to get into.  You may be 
  22. able to find a way to get the system to report that it has 10mb free, but if 
  23. you were to try and allocate 10 - 1mb chunks something would probably fail due 
  24. to fragmentation.  Also, newer operating systems like NT virtualize stuff 
  25. whether you like it or not.  I wrote a sort program once that wanted to use 
  26. all available memory (under NT) and at any given time, a large portion of the 
  27. memory is in use, but can easily be freed up by either throwing it away 
  28. (cached stuff) or swapping it to disk.  You sort of need to ask yourself where 
  29. the line is when you start forcing the OS to swap stuff out that it will need 
  30. real soon or maybe even swapping your sort buffers out (largely defeating the 
  31. purpose).  What happens when the user opens another application after your 
  32. application has taken everything -- you start swapping again.
  33.  
  34. In the case of the sort program, I asked the system how much total real memory 
  35. there was (32mb and this case) and told my sort program (which is designed to 
  36. have primary control of the machine while being ran) to take TOTAL - 8mb (or 
  37. 24mb).
  38.  
  39. All of that said, under DOS4GW (with VM off) I wrote a little function that 
  40. tried to allocate 64mb and then kept shrinking the request (256k at a 
  41. time) until it succeeded.  It then freed the chunk and told me what it could 
  42. get.  This does not give you total available, but does give you the largest 
  43. chunk you might be able to get.  If you do it early in the program and 
  44. remember the number, it will give you a pretty good indication of how much you 
  45. have to work with total (leave a little slack for fragmentation (particularly 
  46. if you are doing large allocations)).
  47.  
  48. BTW, if anybody is doing large allocations (>512k) under WindowsNT I have an 
  49. interesting bug that you might want to know about, if anybody is interested 
  50. drop me a note.
  51.  
  52.  
  53.  
  54. Jeff Petersen
  55. Artificial Software
  56. jeffp@itsnet.com
  57.